home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 …SCII & the Runetime Code / ADC Developer CD (1992-07) (''Butch ASCII And The Runtime Code'')_iso / Dev.CD 199207.iso / Development Platforms / Apple II / HyperCardIIGS / Sample.XCMDs / XWindow Shell / XWindShell (a) / XWindShell.a < prev    next >
Encoding:
Text File  |  1992-02-05  |  12.4 KB  |  400 lines  |  [TEXT/MPS ]

  1. ; ---------------------------------------------------------------------
  2. ;
  3. ;  Assembly source for XWindShell XCMD
  4. ;   
  5. ;  Copyright © 1989-92 Apple Computer, Inc.
  6. ;
  7. ;
  8. ;  This file includes the source code for the XWindShell XCMD.  While
  9. ;  this XCMD will compile and execute in its current form.  The XWindow
  10. ;  has no functionality beyond demonstrating the basics of HyperCard's
  11. ;  XWindow capabilities.  This file is meant to be the basis where an
  12. ;  XCMD author can "fill in the blanks" to create their XCMD.  See the
  13. ;  other sample XCMDs such as Picture, MemState, and ListWindow for
  14. ;  practical examples of code dealing with responding to XWindow events
  15. ;  and strategies for storing information for the XWindows while they
  16. ;  are open.
  17. ;
  18. ;  The files included with the XWindShell XCMD are meant to be
  19. ;  used as a starting point for assembly XCMDs wishing to create and
  20. ;  manage XWindows.
  21. ;
  22. ;  NOTE:  This XCMD is expressly designed to avoid a lot of stack
  23. ;         frame operations.  This is suitable for most XCMDs.  Large,
  24. ;          complex XCMDs may wish to divide the source into smaller,
  25. ;          more manageable procedures with their own local variables.
  26. ;
  27. ;  Files:
  28. ;  ------
  29. ;   *XWindShell.a
  30. ;    XWindShell.r
  31. ;    MakeFile
  32. ;    
  33. ;    
  34. ;  Author:        Darin Acquistapace
  35. ;  Created:        02/04/92
  36. ;  Modified:    See Mod History Below
  37. ;
  38. ;  Modification History:
  39. ;  ---------------------
  40. ;    02/04/92 - New today.
  41. ;     
  42. ; ---------------------------------------------------------------------
  43.  
  44.                 INCLUDE    'E16.Event'
  45.                 INCLUDE    'E16.HyperXCMD'
  46.                 INCLUDE    'New.Stack.Macros'
  47.                 INCLUDE    'M16.Memory'
  48.                 INCLUDE    'M16.Window'
  49.                 INCLUDE    'M16.QuickDraw'
  50.                 INCLUDE    'M16.HyperXCMD'
  51.             
  52.                 LONGA    ON
  53.                 LONGI    ON
  54.         
  55. XWindShell        PROC    EXPORT
  56.  
  57.                 InitFrame
  58.  
  59. ExclamationPt    EQU        $0021                ; ASCII values of "!" & "?"
  60. QuestionMark    EQU        $003f
  61.  
  62. xWindow            Local    Ptr
  63. tempHandle        Local    Handle
  64. tempPtr            Local    Ptr
  65.  
  66. paramPtr        Param    Ptr
  67.  
  68.                 EntryCode
  69.             
  70.                 lda        [<paramPtr]            ; Get the paramCount
  71.                 bpl        NotEventCall        ; If not negative, continue
  72.                 jsr        HandleEvents        ; Otherwise handle the event
  73.                 brl        Exit                ; and leave
  74.                 
  75. NotEventCall    cmp        #01                    ; If we have one parameter,
  76.                 bne        CheckParamCnt        ; check it for "!" or "?"
  77.                 ldy        #oxbParams+2
  78.                 lda        [<paramPtr],y        ; Get a pointer to the first
  79.                 sta        <tempHandle+2        ; zero-terminated param
  80.                 dey
  81.                 dey
  82.                 lda        [<paramPtr],y
  83.                 sta        <tempHandle
  84.                 lda        [<tempHandle]
  85.                 sta        <tempPtr
  86.                 lda        [<tempHandle],y
  87.                 sta        <tempPtr+2
  88.                 
  89.                 lda        [<tempPtr]            ; Get the first param
  90.                 cmp        #ExclamationPt        ; Is it a "!"?
  91.                 bne        CheckQuestion        ; No, check for "?"
  92.                 pea        CopyrightStr>>16
  93.                 pea        CopyrightStr
  94.                 bra        DoSendMessage
  95.                 
  96. CheckQuestion    cmp        #QuestionMark        ; Is it "?"
  97.                 bne        CheckParamCnt        ; No, continue
  98.                 pea        HelpStr>>16
  99.                 pea        HelpStr
  100.                 
  101. DoSendMessage    _SendHCMessage                ; Display the dialog and leave
  102.                 bra        Exit
  103.  
  104. CheckParamCnt    lda        [<paramPtr]            ; Get the paramCount
  105.                 beq        ParamCountOK        ; Zero is OK, o.w. show error
  106.                 bra        HTError
  107.                 
  108. ParamCountOK    jsr        CorrectVersion        ; Make sure we're running HCIIGS
  109.                 bne        VersionOK            ; version 1.1 or later
  110.                 ldx        #WrongVersionStr>>16
  111.                 ldy        #WrongVersionStr
  112.                 bra        ReturnResult
  113.  
  114. VersionOK        pha
  115.                 pha
  116.                 pea        windRect>>16        ; Create the new XWindow init-
  117.                 pea        windRect            ; ially invisible
  118.                 pea        WindTitle>>16
  119.                 pea        WindTitle
  120.                 pea        0                    ; Visible (false)
  121.                 pea        xWindoidStyle
  122.                 _NewXWindow
  123.                 pla    
  124.                 sta        <xWindow
  125.                 pla
  126.                 sta        <xWindow+2
  127.                 ora        <xWindow            ; Make sure the NewXWindow call
  128.                 bne        GoodXWindow            ; succeeded
  129.                 
  130.                 ldx        #CreateErrStr>>16    ; Return an error in the result
  131.                 ldy        #CreateErrStr
  132.                 bra        ReturnResult
  133.  
  134. GoodXWindow        pei        <xWindow+2            ; Set the current port to the
  135.                 pei        <xWindow            ; new xWindow
  136.                 _SetPort
  137.                 
  138.                 jsr     SetUpContents        ; Handle any initialization
  139.                 
  140.                 pei        <xWindow+2            ; Show the xWindow
  141.                 pei        <xWindow
  142.                 _ShowWindow
  143. Exit            
  144.                 ExitCode
  145.  
  146. ; --------------------------------------------------------------------------
  147. HTError
  148. ; Generates a HyperTalk error dialog box complete with Script and Cancel
  149. ; buttons.
  150.                 ldy        #oxbReturnStat        ; Set returnStat to 1
  151.                 lda        #01
  152.                 sta        [<paramPtr],y
  153.                 
  154.                 ldx        #ScriptErrStr>>16    ; Error msg returned in the
  155.                 ldy        #ScriptErrStr        ; result
  156.                 bra        ReturnResult
  157.                 
  158. ; --------------------------------------------------------------------------
  159. ReturnResult
  160. ; Upon entry, x contains the high word of a ptr to a pascal string.  Y
  161. ; contains the low word.  This string is converted to a zero-terminated
  162. ; string.  The handle containing this string is returned in the result.
  163.                 pha                            
  164.                 pha    
  165.                 phx
  166.                 phy
  167.                 _PasToZero
  168.                 ldy        #oxbReturnValue        ; Set returnValue field of
  169.                 pla                            ; the paramBlock to the
  170.                 sta        [<paramPtr],y        ; zero-terminated string
  171.                 iny
  172.                 iny
  173.                 pla
  174.                 sta        [<paramPtr],y
  175.                 bra        Exit
  176.                 
  177. ; --------------------------------------------------------------------------
  178. SetUpContents
  179. ; Our window has been created via a call to the NewXWindow callback and is
  180. ; invisible.  Now handle any initialization necessary for the XWindow such as 
  181. ; calling NewControl, etc.
  182.  
  183.                 rts
  184.                 
  185. ; --------------------------------------------------------------------------
  186. HandleEvents    
  187. ; Handle events specific to our XWindow.  HyperCard will only send events
  188. ; to the XCMD pertaining to windows it has opened.  The XCMD, however, 
  189. ; should not assume that it owns only one window.  Subsequent calls to
  190. ; the XCMD to create the XWindow will result in one XCMD code segment
  191. ; owning multiple XWindows. This routine is similar to the main event loop
  192. ; of an application, all events dealing with the XWindows the XCMD has
  193. ; created will be sent here and dispatched to the appropriate routine to
  194. ; respond to them.
  195.                 ldy        #oxbParams+2        ; Get the ptr to the
  196.                 lda        [<paramPtr],y        ; XWEventInfo record
  197.                 sta        <tempPtr+2
  198.                 dey
  199.                 dey
  200.                 lda        [<paramPtr],y
  201.                 sta        <tempPtr
  202.                 
  203.                 lda        [<tempPtr],y        ; Get the target xWindow
  204.                 sta        <xWindow+2
  205.                 dey
  206.                 dey
  207.                 lda        [<tempPtr],y
  208.                 sta        <xWindow
  209.                 
  210.                 ldy        #04                    ; Get event.what
  211.                 lda        [<tempPtr],y
  212.                 
  213.                 bne        @1                    ; Check against each event
  214.                 bra        ProcessIdle            ; code. (nullEvt)
  215.                 
  216. @1                cmp        #xOpenEvt            ; (xOpenEvt)
  217.                 bne        @2
  218.                 bra        HandleOpenEvent
  219.                 
  220. @2                cmp        #updateEvt            ; (updateEvt)
  221.                 bne        @3
  222.                 bra        UpdateXWindow
  223.                 
  224. @3                cmp        #mouseDownEvt        ; (mouseDownEvt)
  225.                 bne        @4
  226.                 bra        HandleWindClick
  227.                 
  228. @4                cmp        #xHidePalettesEvt    ; (xHidePalettesEvt)
  229.                 beq        @4a
  230.                 cmp        #xShowPalettesEvt    ; (xShowPalettesEvt)
  231.                 bne        @5
  232. @4a                bra        HandleHideShow
  233.                 
  234. @5                cmp        #xCloseEvt            ; (xCloseEvt)
  235.                 bne        @6
  236.                 bra        CleanUpMemory
  237.                 
  238. @6                cmp        #xCursorWithin        ; (xCursorWithin)
  239.                 bne        EventNotHandled
  240.                 bra        HandleCursor
  241.                 
  242. EventNotHandled    rts
  243.  
  244. ; --------------------------------------------------------------------------
  245. ProcessIdle
  246. ; Take any actions that need to be performed periodically.  This procedure
  247. ; will only be called if the SetXWIdleTime callback has been called with
  248. ; an interval value other than zero (the default.)
  249.  
  250.                 rts
  251.                 
  252. ; --------------------------------------------------------------------------
  253. HandleOpenEvent
  254. ; Allow reentrancy, if this is not set, the XWindow may lose events that
  255. ; occur because of events instigated by the XCMD.  For instance, if the
  256. ; mouseDown handler performs some action which causes HyperCard to close
  257. ; the XWindow, the xCloseEvt will not be received because the XCMD has the
  258. ; code in the mouseDown handler pending and will be returned to when Hyper-
  259. ; Card finishes executing whatever task the mouseDown handler began.  This
  260. ; can be set to true for both types of events in most XCMDs and set to false
  261. ; temporarily if the need arises to temporarily halt recursive calls to the
  262. ; XCMD. 
  263. ; If an XCMD wishes to receive null events, it should call SetXWIdleTime
  264. ; at this point with an interval other than zero.
  265.  
  266.                 pei        <xWindow+2
  267.                 pei        <xWindow
  268.                 lda        #01
  269.                 pha
  270.                 pha
  271.                 _XWAllowReEntrancy
  272.                 
  273.                 rts
  274.                 
  275. ; --------------------------------------------------------------------------
  276. UpdateXWindow
  277. ; Handles updating the contents of the XWindow.  This may include drawing 
  278. ; a background picture, calling DrawControls, etc.  HyperCard takes care of 
  279. ; calling BeginUpdate and EndUpdate for you. This routine should only update 
  280. ; the window.  Be careful not to do anything that might cause another update 
  281. ; event to occur which would result in recursion.
  282.  
  283.                 rts
  284.                 
  285. ; --------------------------------------------------------------------------
  286. HandleWindClick
  287. ; A mouseDown event has occurred in our window.  This procedure handles
  288. ; tracking the click and taking whatever actions are necessary as a result
  289. ; of the click. Tracking controls in XWindows is no different than doing
  290. ; the same in any standard window.  FindControl and TrackControl would be
  291. ; commonly used to track the click.  See the Picture and ListWindow sample
  292. ; XCMDs for examples of using the control manager to handle these actions.
  293.  
  294.                 rts
  295.                 
  296. ; --------------------------------------------------------------------------
  297. HandleHideShow
  298. ; An XCMD has called either the HideHCPalettes or ShowHCPalettes callbacks
  299. ; and our visible status has changed.  An XCMD may wish to deallocate memory
  300. ; used for updating the XWindow if it knows it will be hidden for a period of
  301. ; time.  An example usage would be if a significant amount of memory was
  302. ; required to maintain the contents of an XWindow.  A script could call an
  303. ; XCMD to send the HidePalettes event when the user entered the paint tools
  304. ; so that the XCMD could free what memory it could to provide more memory
  305. ; for the paint buffers.
  306.                                 
  307.                 rts
  308.                 
  309. ; --------------------------------------------------------------------------
  310. CleanUpMemory
  311. ; Free all memory associated with the XWindow.  This could be a handle
  312. ; referenced by the GetXWindowValue callback.
  313.  
  314.                 rts
  315.                 
  316. ; --------------------------------------------------------------------------
  317. HandleCursor
  318. ; The mouse cursor is within the XWindow, perform any actions necessary,
  319. ; such as changing the cursor shape.
  320.                 ldy        #oxbPassFlag        ; Let HC handle changing the
  321.                 lda        #01                    ; cursor
  322.                 sta        [<paramPtr],y
  323.                 rts
  324.                 
  325. ; --------------------------------------------------------------------------
  326. MyDisposeHandle
  327. ; Checks a handle for NIL before disposing of it.  A good practice.  Upon
  328. ; entry, x contains high word of handle to be disposed and y contains the
  329. ; low word.
  330.                 
  331.                 stx        <tempHandle            ; Check handle for nil
  332.                 tya
  333.                 ora        <tempHandle
  334.                 beq        @1
  335.                 
  336.                 phx                            ; Not NIL, so dispose it
  337.                 phy
  338.                 _DisposeHandle
  339.  
  340. @1                rts
  341.  
  342. ; --------------------------------------------------------------------------
  343. CorrectVersion
  344. ; This returns 1 in the x reg. if the version of HyperCard is >= minVersion.  
  345. ; Returns 0 in x o.w.  Very important for XCMDs that use callbacks specific 
  346. ; to 1.1 or later versions of HyperCard IIGS.  HyperCard IIGS 1.0 will execute 
  347. ; a BRK and take a one-way trip to the monitor or debugger if an XCMD attempts 
  348. ; an invalid callback number.  HyperCard IIGS 1.1 calls the SysFail manager 
  349. ; with the message, "Invalid callback attempted by XCMD" if a callback numbered 
  350. ; greater than $38 is attempted, BTW.
  351.  
  352.                 pha                            ; Get the version in the form
  353.                 pha                            ; "1.x"
  354.                 pea        versionStr>>16
  355.                 pea        versionStr
  356.                 _EvalExpr
  357.                 pla
  358.                 sta        <tempHandle
  359.                 pla
  360.                 sta        <tempHandle+2
  361.                 
  362.                 ldy        #02                    ; Make a pointer to the zero-
  363.                 lda        [<tempHandle]        ; terminated string handle
  364.                 sta        <tempPtr
  365.                 lda        [<tempHandle],y
  366.                 sta        <tempPtr+2
  367.                 
  368.                 lda        [<tempPtr],y        ; Look at the third character
  369.                 and        #$00ff                ; and compare it against the
  370.                 ldx        #$00                ; ascii char "1"
  371.                 cmp        #'1'
  372.                 blt        @1    
  373.                 inx                            
  374. @1                phx                            ; Save off our result
  375.                 ldx        <tempHandle+2        ; We're responsible for getting
  376.                 ldy        <tempHandle            ; rid of the result of EvalExpr
  377.                 jsr        MyDisposeHandle
  378.                 plx                            ; Restore our result
  379.                 rts
  380.  
  381. ; --------------------------------------------------------------------------
  382. ; Constants used in the XCMD.
  383.  
  384. windRect        dc.w    50, 100, 110, 350
  385.  
  386.                 STRING    PASCAL
  387.                 
  388. versionStr        dc.b    'the version';
  389. WindTitle        dc.b    'SampleXWindow';
  390. ScriptErrStr    dc.b     'Can''t understand arguments of XCMD XWindShell.'
  391. CopyrightStr    dc.b     'answer "XWindShell XCMD v1.0" & return & "by Darin Acquistapace, 1/29/92" & return & "© 1992 Apple Computer, Inc."'
  392. HelpStr            dc.b     'answer "FORM:  XWindShell"'
  393. WrongVersionStr dc.b     'XWindShell XCMD requires HyperCard IIGS 1.1'
  394. CreateErrStr    dc.b     'Unable to create window'
  395.  
  396.                 ENDPROC
  397.                             
  398.                 END
  399.